package components.gamelevels;

import java.awt.Color;
import java.awt.Font;

import scenes.MainGameScene;

import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Label;

import components.ball.NormalBall;
import components.blocks.Block;
import components.blocks.PupBlock;
import components.powerups.PowerUp;
import components.powerups.PowerUpResolver;

public abstract class GameLevel extends MainGameScene {

	private String name;

	private int score;
	private PowerUpResolver pupResolver;
	
	public GameLevel(String levelName, int levelScore, int initialLifes, int initialScore) {
		super(initialLifes, initialScore);
		this.score = levelScore;
		this.name = levelName;
		this.setPupResolver(new PowerUpResolver(this));
		this.addNameLabel();
	}

	private void addNameLabel() {
		Label label = new Label(new Font(Font.DIALOG, Font.PLAIN, 22), Color.WHITE, this.getName());
		GameComponent<GameScene> gc = new GameComponent();
		gc.setAppearance(label);
		gc.setX(350);
		gc.setY(5);
		this.addComponent(gc);
	}

	public abstract BlocksMatrix getMatrix();
	protected abstract GameScene getNextScene(int currentScore, int currentLifes);
	
	protected void allBlocksCleared() {
		this.getScoreGc().add(this.getScore());
		this.getGame().setCurrentScene(this.getNextScene(this.getCurrentScore(), this.getCurrentLifes()));	
	}
	
	public int getCurrentLifes(){
		return this.getLifeCounter().getLifes();
	}
	public int getCurrentScore(){
		return this.getScoreGc().getScore();
	}
	
	protected void addBlocks(){
		BlocksMatrix matrix = this.getMatrix();
		for (Block b : matrix.getBlocks()){
			this.addBlock(b);
		}
	}
	
	public void launchPowerUp(PupBlock pupBlock) {
		PowerUp pup = pupBlock.getPower();
		pup.setX(pupBlock.getX());
		pup.setY(pupBlock.getY());
		this.addCollisionable(pup);
	}
	public void runPowerUp(PowerUp power){
		this.getPupResolver().runPowerUp(power);
	}

	
	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getScore() {
		return score;
	}

	public void setPupResolver(PowerUpResolver pupResolver) {
		this.pupResolver = pupResolver;
	}

	public PowerUpResolver getPupResolver() {
		return pupResolver;
	}




}
